package org.apache.ibatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;

public class Main {

  public static void main(String[] args) throws IOException {
    final SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(Resources.getResourceAsStream("mybatis.xml"));
    final SqlSession sqlSession = sqlSessionFactory.openSession();
    // 首先通过configuration获取sql的声明，然后ParameterHandler处理参数，StatementHandler构建Statement并为Statement设置sql和参数，
    // 最终执行statement，获取的结果集后，通过ResultSetHandler将结果集转换为返回类型
    UserMapper mapper = sqlSession.getMapper(UserMapper.class);
    System.out.println(mapper.selectOne(1L));
  }
}
